package com.huangkailong.gitimgbed;

import cn.hutool.core.io.FileUtil;
import cn.hutool.system.SystemUtil;
import com.huangkailong.gitimgbed.core.GitImgBedApplication;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;

/**
 * @author huangkl
 * @since 1.0.0
 */
@Slf4j
public class Launcher {
    
    public static void main(String[] args) {
        initConfig();
        GitImgBedApplication.main(args);
    }

    private static void initConfig(){
        final String homeDir = SystemUtil.getUserInfo().getHomeDir();
        final String dirPath = homeDir + "/" + ".imgBed";
        FileUtil.mkdir(dirPath);
        final File file = new File(dirPath, "imgBed.properties");
        if(!file.exists()){
            try {
                final boolean created = file.createNewFile();
                if(!created){
                    log.info("配置文件创建失败!");
                    System.exit(-1);
                }
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
